package utils;


import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;

public class DateUtility {
	public static  final SimpleDateFormat dateFormat =  new SimpleDateFormat("yyyy-MM-dd");
	public static  final SimpleDateFormat dateFormat_f =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static  final SimpleDateFormat dateFormat_f2 =  new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
	public static Timestamp getToday() {
		Timestamp today = new Timestamp(new Date().getTime());
		return today;
	}
	
	public static String getTodayS() {
		Timestamp today = new Timestamp(new Date().getTime());
		return dateFormat.format(today);
	}
	
	/**
	 * 获取当前年份信息
	 * @return
	 */
	public static String getYear() {
		LocalDate localDate = LocalDate.now();
		return Integer.toString(localDate.getYear());
	}
	
	public static String getTodayFS() {
		Timestamp today = new Timestamp(new Date().getTime());
		return dateFormat_f.format(today);
	}
	
	public static String getTodayFS2() {
		Timestamp today = new Timestamp(new Date().getTime());
		return dateFormat_f2.format(today);
	}
	
	public static Date formStartDate(Date date){
		Date formatDate = new Date(date.getTime());

		formatDate.setHours(0);
		formatDate.setMinutes(0);
		formatDate.setSeconds(0);

		return formatDate;
	}

	public static Date formEndDate(Date date){
		Date formatDate = new Date(date.getTime());

		formatDate.setHours(23);
		formatDate.setMinutes(59);
		formatDate.setSeconds(59);
		return formatDate;
	}
	
	public static Date getLastMonthDay() {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MONTH, -1);
		Date today = new Date(calendar.getTimeInMillis());
		return today;
	}
	
	public static Date getNextDay(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DATE, 1);
		Date today = new Date(calendar.getTimeInMillis());
		return today;
	}
	
	public static Date getPriorMonthDay(int lastAmt) {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MONTH, -1 * lastAmt);
		Date today = new Date(calendar.getTimeInMillis());
		return today;
	}
	
	public static int getDateInterval(Date date1, Date date2){
		   long intervalMilli = Math.abs(date1.getTime() - date2.getTime());
		   
	       return (int) (intervalMilli / (24 * 60 * 60 * 1000));
	}
		
	
}
